function comment(){
      var cont = $('#cont').val();
    if (cont==''){
        $(cont).focus();
        layer.tips('说点什么吧','#cont', {tips:1});
        return false;     
    }   
    $.post('post.php',{cont:cont},function(msg){
        if (msg == 'ok'){
            $('<div class="msg clearfix on"><div class="img1"><img src="img/kefu.png" alt="" width="100%"></div><div class="img2"><img src="img/user.png" alt="" width="100%"></div><div class="content"><span>'+cont+'</span><div class="indicate left-indicate"></div><div class="indicate right-indicate"></div></div></div>').appendTo($('#msgzone'));
            $(".msg-box").scrollTop(99999999);
        }else{
            layer.msg(msg);
        }
    });

    document.querySelector("textarea").value = "";
}
$(document).keydown(function(event){
    if (event.keyCode == 13) {
        comment();
        event.returnValue = false;
        return false;
    }
});
function upload(){
    var formdata=new FormData(); 
    formdata.append("file" , $("#file")[0].files[0]);
    $.ajax({
        type : 'post',
        url : 'img.php',
        data : formdata,
        cache : false,
        processData : false,
        contentType : false, 
        success : function(json){
            var reg = RegExp(/upload/);
            if(json.match(reg)){
                $('<div class="msg clearfix on"><div class="img1"><img src="img/kefu.png" alt="" width="100%"></div><div class="img2"><img src="img/user.png" alt="" width="100%"></div><div class="content"><img src="'+json+'" width="100%"><div class="indicate left-indicate"></div><div class="indicate right-indicate"></div></div></div>').appendTo($('#msgzone'));
                var top=999999999;
                var startTime = new Date().getTime();
                var interval = setInterval(function(){
                    if(new Date().getTime() - startTime > 2000){
                    clearInterval(interval);
                    return;
                    }
                $(".msg-box").scrollTop(top++);
                }, 1);
            }else{
                layer.msg(json);
            }	
        }  
    })
}
window.onload = function(){
    $.post('status.php',{status:1,login:1} ,function(firstmsg){
        if(firstmsg[0] < 1){
            var audio = new Audio();
            audio.src = 'msg.mp3' ;
            audio.play();
        }else{
            $(".msg-box").scrollTop(99999999);
        }
        document.querySelector("#first-msg").innerHTML = firstmsg[1];
    }, "json");
}
document.addEventListener('visibilitychange',function(){
    var isHidden = document.hidden;
    if(isHidden){	
    $.post('status.php',{status:2});
    } else {
    $.post('status.php',{status:1});
    $(".msg-box").scrollTop(99999999);
    }
});

$.ajaxSetup ({ cache: false });
setInterval(function(){
    $.getJSON("user_data.php", function(data){
        var audio = new Audio();
        audio.src = 'msg.mp3' ;
        audio.play();	
        $('<div class="msg clearfix"><div class="img1"><img src="img/kefu.png" alt="" width="100%"></div><div class="img2"><img src="img/user.png" alt="" width="100%"></div><div class="content"><span>'+data+'</span><div class="indicate left-indicate"></div><div class="indicate right-indicate"></div></div></div>').appendTo($('#msgzone'));
        var top=999999999;
        var startTime = new Date().getTime();
        var interval = setInterval(function(){
            if(new Date().getTime() - startTime > 2000){
            clearInterval(interval);
            return;
            }
        $(".msg-box").scrollTop(top++);
        }, 1);
    });	
    $.post('status.php');
}, 1000);